using System;

using System.Drawing;
using System.Drawing.Drawing2D;

namespace GDIdotNETgames
{
    public class ClassCamera
    {
        private Matrix _transform = new Matrix();
        private Rectangle _screen = new Rectangle();

        public Matrix Transform
        {
            get { return _transform; }
            set { _transform = value; }
        }
        public SizeF Scale
        {
            get
            {
                return new SizeF(
                    (float)Math.Sqrt(_transform.Elements[0] * _transform.Elements[0] + _transform.Elements[2] * _transform.Elements[2]),
                    (float)Math.Sqrt(_transform.Elements[1] * _transform.Elements[1] + _transform.Elements[3] * _transform.Elements[3]));
            }
        }
        public PointF Location
        {
            get
            {
                return new PointF(
                    -_transform.OffsetX / Scale.Width,
                    -_transform.OffsetY / Scale.Height);
            }
            set
            {
                _transform.Translate(
                    -(value.X + _transform.OffsetX / Scale.Width),
                    -(value.Y + _transform.OffsetY / Scale.Height),
                    MatrixOrder.Prepend);
            }
        }
        public SizeF Size
        {
            get
            {
                return new SizeF(
                    _screen.Width / Scale.Width,
                    _screen.Height / Scale.Height);
            }
            set { _transform.Scale(Size.Width / value.Width, Size.Height / value.Height, MatrixOrder.Append); }
        }
        public RectangleF Viewport
        {
            get { return new RectangleF(Location, Size); }
            set
            {
                Location = value.Location;
                Size = value.Size;
            }
        }
        public Rectangle Screen
        {
            get { return _screen; }
            set { _screen = value; }
        }

        public ClassCamera(Rectangle screen)
        {
            _screen = screen;
        }
    }
}
